package task.manager;

import java.util.ArrayList;
import java.util.List;

/**
 * Sorts tasks by date.
 * 
 * @author Harrison Saylor, Aaron Mead, Marc Huet, Greg Ruskin
 * @version 2
 */
public class TaskSorterDate implements TaskSorter{
	UserDataFacade userDataFacade;
	String activeCategory;
	
	int month;
	int day;
	int year;
	
	public TaskSorterDate() {
		userDataFacade = UserDataFacade.getInstance();
		month = userDataFacade.getSortMonth();
		day = userDataFacade.getSortDay();
		year = userDataFacade.getSortYear();
		
	}
	
	@Override
	public String[] getSortedTaskArray(String category) {
		TaskList taskList = userDataFacade.getTaskList();
		activeCategory = category;
		List<String> tempArray = new ArrayList<String>();
		
		if(activeCategory.equals("All")){
			for(int i = 0;i<taskList.size();i++){
				if(taskList.get(i).isAfter(month,day,year)){
					tempArray.add(taskList.get(i).getTitle());
				}
			}
		}
		else{
			for(int i = 0;i<taskList.size();i++){
				if(taskList.catNameEquals(i,activeCategory)){
					if(taskList.get(i).isAfter(month,day,year)){
						tempArray.add(taskList.get(i).getTitle());
					}
				}
			}
			tempArray.add("Add New Task");
		}
		
		
		
		String[] retArray = new String[tempArray.size()];
		tempArray.toArray(retArray);
		
		return retArray;
	}
}
